package com.song.estore.service;

import com.song.estore.dao.UserDao;
import com.song.estore.domain.User;
import com.song.estore.utils.IDUtils;
import com.song.estore.utils.MD5Utils;

/**
 * Created by 范姣姣 on 2015/10/22.
 */
public class UserService {

    private UserDao userDao;


    public boolean findemailExists(String email) {
        return userDao.findUserExists(email);
    }

    public boolean addUser(User user){

        user.setPassword(MD5Utils.getPassword(user.getPassword()));
        user.setActivecode(IDUtils.getId());
        user.setActive(0);
        user.setRole("user");
        return userDao.addUser(user) == 1;
    }


    public User findUserLogin(String email,String password){
        String new_pwd = MD5Utils.getPassword(password);
        User user = null;
        user = userDao.findbyPassword(email,new_pwd);
        return null == user ? null:user;
    }



    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
